<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-row>
      <el-col :span='22' :xs='24'>
        <el-form ref="form" :model="s_part" :rules="rules" label-width="100px" id="mvcfm">
          <el-button @click="gotoPage('/mes/certificate/AddCertificateRelation?'+vueparams+'')" type='success' size="mini"><i class='fa fa-plus'></i>增加证书关系</el-button>
          <el-button @click="d_batch_product('')" type='success' size="mini"><i class='fa fa-check'></i>批量删除</el-button>
          <div class="form-unit">
            <span class="mvc-title-left"> 关系 </span>
          </div>
          <el-table :data="s_part" @selection-change="handleSelectionChange">
            <el-table-column label="#" align="center" type='selection'>
            </el-table-column>
            <el-table-column label="#" align="center" type='index'>
            </el-table-column>
            <el-table-column label="产品名称" prop="re_part_id">
              <template slot-scope="scope">
                <el-link @click="popEstablishRelation('&CMIDrelation_id='+scope.row.re_part_id+'')" type='primary'>{{scope.row.product_name}}</el-link>
              </template>
            </el-table-column>
            <el-table-column label="规格" prop="norm">
            </el-table-column>
            <el-table-column label="型号" prop="model">
            </el-table-column>
            <el-table-column label="关系名称" prop="general_name">
            </el-table-column>
          </el-table>
          <pagination v-show="total>0" :total="total" :limit.sync="pageSize" @pagination="getPage" />
        </el-form>
      </el-col>
      <el-col :span='2' :xs='24'>
        <el-menu default-active='active' class='menu-unit'>
          <el-menu-item v-for='item in Container'>
            <el-link @click="gotoMenu(item.url)" :type="'证书关系'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="EstablishRelationVisible" append-to-body>
      <EstablishRelation v-if="EstablishRelationVisible" ref="EstablishRelation" :popparams="popparams"> </EstablishRelation>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import EstablishRelation from "@/views/mes/certificate/EstablishRelation";
  export default {
    name: 'CertificateRelation',
    components: {
      EstablishRelation,
    },
    props: ['popparams'],
    data() {
      return {
        EstablishRelationVisible: false,
        EstablishRelationValue: null,
        EstablishRelationDesc: null,
        vueparams: this.getVUEParams(""),
        s_part: [],
        loading: false,
        Container: null,
        elcheck: [],
        multiple: true,
        rules: {}
      }
    },
    created() {
      this.getData();
      this.loadContainerMenu({
        pid: "018E412E935E4B3EB6DF631BB3B46A50",
        name: "客户右菜单类型",
        selected: "证书关系"
      }, 'Container', this.vueparams);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/certificate/CertificateAction/certificateRelation?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      d_batch_product(_params) {
        this.$confirm("确认批量删除", "警告").then(() => {
          request({
            method: 'post',
            url: '/xcapi/VUEAction/mes/certificate/CertificateAction/d_batch_product?' + _params + this.vueparams,
            data: this.postData()
          }).then(data => {
            this.$router.replace("/redirect" + this.$route.fullPath);
            this.msgSuccess(data.msg);
          })
        });
      },
      popEstablishRelation(params) {
        if (params != "") this.popparams = params + this.vueparams;
        this.EstablishRelationVisible = !this.EstablishRelationVisible;
      },
      handleSelectionChange(selection) {
        this.elcheck = selection.map(item => item["re_part_id"]);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
    },
  }
</script>
